package com.youlu.campus.admin.community.controller;

import com.youlu.campus.admin.utils.AuthUtils;
import com.youlu.campus.entity.ActivityCmsSlideshow;
import com.youlu.campus.entity.VO.req.ActivityCmsSlideshowQueryVO;
import com.youlu.campus.service.activity.ActivityCmsSlideshowService;
import com.yuelin.infrastructure.quantum.common.QResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

@Slf4j
@RestController
public class ActivityCmsSlideshowController {
    @Autowired
    private ActivityCmsSlideshowService activityCmsSlideshowService;

    @PostMapping("/activity/cms-slideshow/create")
    public QResult createActivityTask(@RequestBody @NotNull ActivityCmsSlideshow request) {
        request.setCreatorId(AuthUtils.getUserId());
        boolean result = activityCmsSlideshowService.create(request);
        return QResult.success(result);
    }

    @PostMapping("/activity/cms-slideshow/update")
    public QResult updateActivityTask(@RequestBody ActivityCmsSlideshow request) {
        boolean result = activityCmsSlideshowService.update(request);
        return QResult.success(result);
    }

    @GetMapping("/activity/cms-slideshow/delete")
    public QResult deleteActivityTask(@RequestParam("id") String id) {
        boolean result = activityCmsSlideshowService.delete(id);
        return QResult.success(result);
    }

    @PostMapping("/activity/cms-slideshow/list")
    public QResult activityListTask(@RequestBody ActivityCmsSlideshowQueryVO request) {
        try {
            return QResult.success(activityCmsSlideshowService.list(request));
        } catch (Exception e) {
            log.error(":>>> 活动任务列表错误:{}", e);
            return QResult.fail("活动任务列表错误");
        }

    }

    @GetMapping("/activity/cms-slideshow/find-one")
    public QResult getActivityTask(@RequestParam("id") String id) {
        return QResult.success(activityCmsSlideshowService.find(id));
    }
}
